/*
 * (C) Copyright 2023 orchy
 * This file is licensed under the BSD-3-Clause license.
 * <https://spdx.org/licenses/BSD-3-Clause.html>
 */
#ifndef _STDLIB_H
#define _STDLIB_H

// # 7.20.0
// ## 7.20.0.2
#ifndef _SIZE_T_DEFINED
  typedef long long int size_t;
  #define _SIZE_T_DEFINED
#endif
#ifndef _WCHAR_T_DEFINED
  typedef long long int wchar_t;
  #define _WCHAR_T_DEFINED
#endif

typedef struct div_t {
	int quot;
	int rem;
} div_t;
typedef struct ldiv_t {
	long int quot;
	long int rem;
} ldiv_t;
typedef struct lldiv_t {
	long long int quot;
	long long int rem;
} lldiv_t;
// ## 7.20.0.3
#ifndef NULL
#define NULL ((void*)0)
#endif
#define EXIT_FAILURE (1)
#define EXIT_SUCCESS (0)
#define RAND_MAX (2000000000)
#define MB_CUR_MAX (4)

// # 7.20.1
// ## 7.20.1.1
double atof(const char* nptr);

// ## 7.20.1.2
int atoi(const char* nptr);
long int atol(const char* nptr);
long long int atoll(const char* nptr);

// ## 7.20.1.3
double strtod(const char* restrict nptr, char** restrict endptr);
float strtof(const char* restrict nptr, char** restrict endptr);
long double strtold(const char* restrict nptr, char** restrict endptr);

// ## 7.20.1.4
long int strtol(const char* restrict nptr, char** restrict endptr, int base);
long int strtoll(const char* restrict nptr, char** restrict endptr, int base);
unsigned long int strtoul(const char* restrict nptr, char** restrict endpre, int base);
unsigned long long int strtoull(const char* restrict nptr, char** restrict endptr, int base);

// # 7.20.2
// ## 7.20.2.1
int rand(void);

// ## 7.20.2.2
void srand(unsigned int seed);

// # 7.20.3
// ## 7.20.3.1
void* calloc(size_t nmemb, size_t size);

// ## 7.20.3.2
void free(void* ptr);

// ## 7.20.3.3
void* malloc(size_t size);

// ## 7.20.3.4
void* realloc(void* ptr, size_t size);

// # 7.20.4
// ## 7.20.4.1
void abort(void);

// ## 7.20.4.2
int atexit(void (*func)(void));

// ## 7.20.4.3
void exit(int status);

// ## 7.20.4.4
void _Exit(int status);

// ## 7.20.4.5
char* getenv(const char* name);

// ## 7.20.4.6
int system(const char* string);

// # 7.20.5
// ## 7.20.5.1
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));

// ## 7.20.5.2
void qsort(void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*));

// # 7.20.6
// ## 7.20.6.1
int abs(int j);
long int labs(long int j);
long long int llabs(long long int j);

// ## 7.20.6.2
div_t div(int numer, int denom);
ldiv_t ldiv(long int numer, long int denom);
lldiv_t lldiv(long long int numer, long long int denom);

// # 7.20.7
// ## 7.20.7.1
int mblen(const char* s, size_t n);

// ## 7.20.7.2
int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);

// ## 7.20.7.3
int wctomb(char* s, wchar_t wc);

// # 7.20.8
// ## 7.20.8.1
size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);

// ## 7.20.8.2
size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);

#endif

